package com.wkk.controller;

import com.wkk.entity.*;
import com.wkk.service.ChatService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;


@Controller
public class ChatController {

    @Autowired
    private ChatService chatService;

    /**
     * 获取所有朋友圈
     * @param uid 调用该接口的用户编号（用于检测该用户点赞或评论某朋友圈）
     * @return
     */
    @ResponseBody
    @RequestMapping("getAllRecords")
    public List<ChatRecord> getAllRecords(@RequestParam("uid")Integer uid){
        ///ModelAndView mav = new ModelAndView("chatPage");
        //mav.addObject("chatRecords",chatService.queryChatRecordByCondition(uid,"all").getChatRecords());
        //return mav;
        return chatService.queryChatRecordByCondition(uid,"all",0).getChatRecords();
    }

    /**
     * 获取关注用户的朋友圈信息
     * @param uid 调用该接口的用户编号（用于获取该用户关注的用户的朋友圈，并检测该用户点赞或评论某朋友圈）
     * @return
     */
    @ResponseBody
    @RequestMapping("getAttentionRecords")
    public List<ChatRecord> getAttentionRecords(@RequestParam("uid")Integer uid){
       //  ModelAndView mav = new ModelAndView("chatPage");
       //  mav.addObject("chatRecords",chatService.queryChatRecordByCondition(uid,"attention").getChatRecords());
       // return mav;
        return chatService.queryChatRecordByCondition(uid,"attention",0).getChatRecords();
    }

    /**
     * 获取一位用户的信息（粉丝数，发布过的朋友圈信息）
     * @param uid 这位用户的编号
     * @param fan 若为空则为访问自己的朋友圈页面
     * @return
     */
    @ResponseBody
    @RequestMapping("getUserRecords")
    public User getUserRecords(@RequestParam("uid")Integer uid,
                                           @RequestParam(value = "fan",required = false,defaultValue = "0")Integer fan){
       // ModelAndView mav = new ModelAndView("chatPageUser");
       //  mav.addObject("starInfo",chatService.queryChatRecordByCondition(uid,"one"));
       // return mav;
        return chatService.queryChatRecordByCondition(uid,"one",fan);
    }

    /**
     * 点赞
     * @param chatLike
     * @return
     */
    @ResponseBody
    @RequestMapping("likeOneChat")
    public String likeOneChat(ChatLike chatLike){
        chatService.likeOneChat(chatLike);
        return "1";
    }

    /**
     * 取消赞
     * @param chatLike
     * @return
     */
    @ResponseBody
    @RequestMapping("dislikeOneChat")
    public String dislikeOneChat(ChatLike chatLike){
        chatService.dislikeOneChat(chatLike);
        return "1";
    }

    /**
     * 关注用户
     * @param chatUser
     * @return
     */
    @ResponseBody
    @RequestMapping("attentionOne")
    public String attentionOne(ChatUser chatUser){
        chatService.attentionOne(chatUser);
        return "1";
    }

    /**
     * 取消关注
     * @param chatUser
     * @return
     */
    @ResponseBody
    @RequestMapping("notAttentionOne")
    public String notAttentionOne(ChatUser chatUser){
        chatService.notAttentionOne(chatUser);
        return "1";
    }

    /**
     * 删除某朋友圈
     * @param crid
     * @return
     */
    @ResponseBody
    @RequestMapping("deleteChatRecord")
    public String deleteChatRecord(@RequestParam("crid")Integer crid){
        chatService.deleteChatRecord(crid);
        return "1";
    }

    /**
     * 发布朋友圈
     * @param chatRecord
     * @return
     */
    @ResponseBody
    @RequestMapping("addChatRecord")
    public String addChatRecord(ChatRecord chatRecord){
        chatService.addChatRecord(chatRecord);
        return "1";
    }

    /**
     * 删除某条评论
     * @param ccid
     * @return
     */
    @ResponseBody
    @RequestMapping("deleteCommentByCCid")
    public String deleteCommentByCCid(@RequestParam("ccid")Integer ccid){
        chatService.deleteComment(ccid);
        return "1";
    }

    /**
     * 获取某用户的历史评论
     * @param uid
     * @return
     */
    @ResponseBody
    @RequestMapping("getHistoryCommentByUid")
    public List<ChatComment> getHistoryCommentByUid(@RequestParam("uid")Integer uid){
        return chatService.queryCommentByUid(uid);
    }

    /**
     * 发表评论
     * @param chatComment
     * @return
     */
    @ResponseBody
    @RequestMapping("addComment")
    public String addComment(ChatComment chatComment){
        chatService.addComment(chatComment);
        return "1";
    }


    //权限接口暂时不写
}
